<?php

namespace App\Admin\Controllers\Agents;

use App\Admin\Repositories\AgentAccount;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AgentAccountController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new AgentAccount(), function (Grid $grid) {
            $grid->model()->with('agent')->orderBy('created_at','desc');
            $grid->column('id')->sortable();
            $grid->column('agent_id')->filter();
            $grid->column('agent.username','代理');
            $grid->column('balance');
            $grid->column('profits');
            $grid->column('withdrawed');
            $grid->column('bank_receiver');
            $grid->column('bank_name');
            $grid->column('bank_number');
            $grid->column('ali_account');
            $grid->column('ali_qr')->image('http://'.$_SERVER["HTTP_HOST"].'/storage/images/agents/',100,100);
            $grid->column('wx_receiver');
            $grid->column('wx_qr')->image('http://'.$_SERVER["HTTP_HOST"].'/storage/images/agents/',100,100);
            $grid->column('edit_code')->copyable();
            $grid->column('updated_at')->sortable();
        
            $grid->disableCreateButton();
            $grid->disableBatchActions();
            $grid->disableDeleteButton();
            $grid->disableEditButton();
            // $grid->disableActions();
            // $grid->disableFilterButton();
            $grid->quickSearch(['agent_id','bank_name','ali_account','wx_receiver']);
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('agent_id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new AgentAccount(), function (Show $show) {
            $show->field('id');
            $show->field('agent_id');
            $show->field('balance');
            $show->field('profits');
            $show->field('withdrawed');
            $show->field('bank_receiver');
            $show->field('bank_name');
            $show->field('bank_number');
            $show->field('ali_account');
            $show->field('ali_qr')->image('http://'.$_SERVER["HTTP_HOST"].'/storage/images/agents/',100,100);
            $show->field('wx_receiver');
            $show->field('wx_qr')->image('http://'.$_SERVER["HTTP_HOST"].'/storage/images/agents/',100,100);
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new AgentAccount(), function (Form $form) {
            $form->display('id');
            $form->display('agent_id');
            $form->display('balance');
            $form->display('profits');
            $form->display('withdrawed');
            // $form->text('bank_receiver');
            // $form->text('bank_name');
            // $form->text('bank_number');
            // $form->text('ali_account');
            // $form->text('ali_qr');
            // $form->text('wx_receiver');
            // $form->text('wx_qr');
            $form->text('edit_code');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
